//
//  DudsTableViewCell.m
//  BaseFrame
//
//  Created by ENERGY on 2018/5/2.
//  Copyright © 2018年 com.mxh. All rights reserved.
//

#import "DudsTableViewCell.h"

@interface DudsTableViewCell()
@property (strong, nonatomic)UILabel *titleLabel;
@property (strong, nonatomic)UIImageView *arrowImgView;
@property (nonatomic, strong)UIView * lineView;
@property (nonatomic, strong)UITextField * contentTextField;
@property (nonatomic, strong)UILabel * contentLab;

@end
@implementation DudsTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.arrowImgView];
        [self.contentView addSubview:self.lineView];
        [self.contentView addSubview:self.contentTextField];
        [self.contentView addSubview:self.contentLab];

        __weak typeof (self)weakSelf = self;
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.mas_left).offset(10 / WIDTH_5S_SCALE);
            make.top.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
            make.width.mas_equalTo(60/WIDTH_5S_SCALE);
        }];
        [self.contentTextField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.titleLabel.mas_right).offset(3 / WIDTH_5S_SCALE);
            make.top.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
        }];
        [self.contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.titleLabel.mas_right).offset(3 / WIDTH_5S_SCALE);
            make.top.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
            make.right.equalTo(weakSelf.mas_right).offset(-10/WIDTH_5S_SCALE);
        }];
        [self.arrowImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-15 / WIDTH_5S_SCALE);
            make.top.mas_equalTo(0);
            make.bottom.mas_equalTo(0);
            make.width.mas_equalTo(7 / WIDTH_5S_SCALE);
        }];
        [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(10 / WIDTH_5S_SCALE);
            make.bottom.mas_equalTo(0);
            make.height.mas_equalTo(0.5);
            make.right.mas_equalTo(-10 / WIDTH_5S_SCALE);
        }];
    }return self;
}

#pragma mark - init
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel  = [[UILabel alloc]init];
        _titleLabel.font = DEF_FontSize_14;
        _titleLabel.textColor = getColor(textColor);
    }return _titleLabel;
}

- (UILabel *)contentLab{
    if (!_contentLab) {
        _contentLab  = [[UILabel alloc]init];
        _contentLab.font = DEF_FontSize_14;
        _contentLab.textColor = getColor(textColor);
        _contentLab.userInteractionEnabled = YES;
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(choosePlace:)];
        [_contentLab addGestureRecognizer:tap];
    }return _contentLab;
}

- (UIImageView *)arrowImgView{
    if (!_arrowImgView) {
        _arrowImgView = [UIImageView new];
        _arrowImgView.contentMode = UIViewContentModeScaleAspectFit;
    }return _arrowImgView;
}

- (UIView *)lineView{
    if (!_lineView) {
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = getColor(dividerColor);
    }return _lineView;
}

- (UITextField *)contentTextField{
    if (!_contentTextField) {
        _contentTextField = [[UITextField alloc] init];
        _contentTextField.font = DEF_FontSize_14;
    }return _contentTextField;
}
//跳转页面
- (void)choosePlace:(UITapGestureRecognizer *)tap{
    if (self.choosePlace) {
        self.choosePlace();
    }
}

- (void)setModel:(NSDictionary *)model{
//flag：1、有箭头   2、没箭头
    //isTextField：1、textfield  2、label
    _model = model;
    self.titleLabel.text = model[@"title"];
    self.contentTextField.placeholder = model[@"placeHolder"];
    if ([model[@"flag"] isEqualToString:@"1"]) {
        self.arrowImgView.image = [UIImage imageNamed:@"right_image"];
    }else{
        self.arrowImgView.image = nil;
    }
    if ([model[@"isTextField"] isEqualToString:@"1"]) {
        self.contentTextField.hidden = NO;
        self.contentLab.hidden = YES;
    }else{
        self.contentTextField.hidden = YES;
        self.contentLab.hidden = NO;
    }
}

@end
